import axios from "axios";
import {generateRandomString} from "@/utils/index.js";
import {message} from "ant-design-vue";

const baseConfig = {
    baseURL: '/admin',
    timeout: 60 * 1000
}
const http = axios.create(baseConfig)
http.interceptors.request.use((config) => {
        config.headers['Authorization'] = `oAuth ${generateRandomString(256)}`
        return config
    },
    (error) => {
        return Promise.reject(error)
    })
http.interceptors.response.use((res) => {
        const {code, msg, data} = res.data
        if (!code) {
            return data
        } else {
            message.error(msg)
        }
    },
    (err) => {
        message.error(err.message)
        return Promise.reject(err)
    })
export default http